﻿using System;

namespace SuperFrame.Charts
{
    public static class AxisUtil
    {
        /// <summary>
        /// 计算距离
        /// <param name="min">最小</param>
        /// <param name="max">最大</param>
        /// <param name="intervalCount">区间数</param>
        /// <returns>Interval</returns>
        public static double CalculateInetrval(double min, double max, double intervalCount)
        {
            double range = max - min;
            // 计算一个步长的初始猜测
            double tempInterval = range / intervalCount;

            //获取步长大小的大小
            double mag = Math.Floor(Math.Log10(tempInterval));
            double magPow = Math.Pow(10, mag);

            // 计算新步长的最重要的数字
            double magMsd = (int)(tempInterval / magPow + 0.5);

            // promote the MSD to either 1, 2, or 5
            if (magMsd > 5.0)
            { }
            else if (magMsd > 3.0)
                magMsd = 3.0f;
            else if (magMsd > 2.0)
                magMsd = 5.0f;
            else if (magMsd > 1.0)
                magMsd = 2.0f;

            return magMsd * magPow;
        }

        //public static double CalculateIntervalNew(double min, double max, double intervalCount)
        //{
            
        //}
    }
}
